import React from 'react'
import styles from './index.less'
import defaulImg from './img/default.png'
import defaulLogo from './img/defaultLogo.png'
import { useHistory } from 'dva'
import { E } from '../../../../constants'
import { useDispatch, useSelector } from 'dva'
import { getToken } from '../../utils/authority'
import { getLocale } from 'umi';

function Index({ imgSrc, company, iconIndex, area, obj }) {
  const { userInfo } = useSelector(({ index }) => index)
  const history = useHistory()
  const dispatch = useDispatch()
  const id = 1
  const lang = () => getLocale()?.split('-')[0]?.toUpperCase();
  function filterData() {
    let name = '';
    let area = '';
    let img = '';
    let logo = ''
    if (obj) {
      name = lang() === 'ZH' ? obj.name : obj.nameEn;
      img = obj.properties.coverImage ? obj.properties.coverImage : '';
      logo = obj.properties.logo ? obj.properties.logo : '';
      area = obj.province ? obj.province : ''
    }
    return {
      name,
      img,
      logo,
      area
    }
  }
  let data = filterData()
  // console.log(data, 'data')
  return (
    <div className={styles.box} onClick={() => {
      // let token = getToken()
      // if (!token) {
      //   dispatch({
      //     type: 'index/setState',
      //     payload: {
      //       loginModalShow: true
      //     }
      //   })
      //   return
      // }
      history.push(`/index/exhibitorDetail/${obj && obj.id}`)
    }}>
      <div className={styles.imgBxo}>
        <img src={data.img}></img>
      </div>
      <div className={styles.infoBox}>
        <div>
          <img src={data.logo}></img>
          <span className={styles.title}>{data.name}</span>
        </div>
        <span className={styles.area}>{data.area}</span>
      </div>
    </div>
  )
}

export default Index
